package com.woyou.ui.adapter;

import java.util.List;

import com.citaq.ideliver.R;
import com.woyou.bean.GoodsType;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 菜品列表的过滤选项
 * 
 * @author shenzhou	2015年1月20日
 */
public class GoodsTypeAdapter extends BaseAdapter {
	
	private Context mContext;
	private List<GoodsType> goodsTypeList = null;
	
	public GoodsTypeAdapter(Context mContext, List<GoodsType> goodsTypeList) {
		super();
		this.mContext = mContext;
		this.goodsTypeList = goodsTypeList;
	}

	@Override
	public int getCount() {
		return goodsTypeList.size();
	}

	@Override
	public Object getItem(int position) {
		return goodsTypeList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if ( convertView == null ) {
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.item_goodstype_lv, null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView.findViewById(R.id.goodstype_name);
			holder.num = (TextView) convertView.findViewById(R.id.goodstype_num);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		GoodsType goodsType = goodsTypeList.get(position);
		holder.name.setText(goodsType.gettName());
//		if ( !TextUtils.isEmpty(goodsType.getNum()) ){
//			holder.num.setText("(" + goodsType.getNum() + ")");
//		} else {
//			holder.num.setVisibility(View.GONE);
//		}
		return convertView;
	}
	
	static class ViewHolder {
		TextView name;
		TextView num;
	}
}
